package com.dycx.user.converter;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dycx.user.dto.QrCodeDTO;
import com.dycx.user.entity.QrCodeDO;
import com.dycx.user.vo.QrCodeVO;
import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * (QrCode)实体转换类
 *
 * @author makejava
 * @since 2024-08-06 22:03:10
 */


@Data
public class QrCodeConverter implements Serializable {
    public static QrCodeDO dtoToEntity(QrCodeDTO dto) {
        if (dto == null) return null;
        QrCodeDO entity = BeanUtil.toBean(dto, QrCodeDO.class);
        return entity;
    }

    public static QrCodeVO entityToVo(QrCodeDO entity) {
        if (entity == null) return null;
        QrCodeVO vo = BeanUtil.toBean(entity, QrCodeVO.class);

        return vo;
    }

    public static List<QrCodeVO> entityToVoList(List<QrCodeDO> entityList) {
        List<QrCodeVO> voList = new ArrayList<>();
        for (QrCodeDO entity : entityList) {
            voList.add(entityToVo(entity));
        }
        return voList;
    }

    public static Page<QrCodeVO> entityToVoPage(Page<QrCodeDO> page) {

        List<QrCodeVO> newRecords = new ArrayList<>();

        List<QrCodeDO> records = page.getRecords();
        for (QrCodeDO entity : records) {
            newRecords.add(entityToVo(entity));
        }

        Page<QrCodeVO> voPage = new Page<>();
        voPage.setRecords(newRecords);
        voPage.setPages(page.getPages());
        voPage.setTotal(page.getTotal());
        voPage.setSize(page.getSize());
        voPage.setCurrent(page.getCurrent());

        return voPage;
    }

}
